﻿using System;
using TIS.DAO;

namespace TIS.UserControl
{
    public partial class NewsRight : System.Web.UI.UserControl
    {
        CategoryDAO _categoryDao = new CategoryDAO();
        NewsDAO _newsDao = new NewsDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["lang"] == null)
                {
                    Session["lang"] = 1;

                }
                if (Request.QueryString["catId"] != null)
                {

                    BindNewsRight();
                    BindNews2();
                }
                else
                {
                    Response.Redirect("/Home/Default.aspx");
                }

            }
        }

        public void BindNewsRight()
        {


            string id = Request.QueryString["catId"];
            int langId = int.Parse(Session["lang"].ToString());
            if (int.Parse(id) == 1)
            {
                rpTitleRight.DataSource = _categoryDao.GetCategory(3, langId);
                rpTitleRight.DataBind();
                rpNewsRight.DataSource = _newsDao.GetNewsRight(3, langId);
                rpNewsRight.DataBind();
            }
            else
            {
                rpTitleRight.DataSource = _categoryDao.GetCategory(1, langId);
                rpTitleRight.DataBind();
                rpNewsRight.DataSource = _newsDao.GetNewsRight(1, langId);
                rpNewsRight.DataBind();
            }

        }

        public void BindNews2()
        {
            int langId = int.Parse(Session["lang"].ToString());
            rpTitle2.DataSource = _categoryDao.GetCategory(5, langId);
            rpTitle2.DataBind();

            rpNews2.DataSource = _newsDao.GetNewsRight(5, langId);
            rpNews2.DataBind();
        }
    }
}